package com.example.envatoandroid;

import org.w3c.dom.UserDataHandler;

import com.example.envatoandroid.db.UserInfoData;
import com.example.envatoandroid.db.UserInfoDataManager;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;



public class LoginActivity extends Activity  implements OnClickListener{

	private EditText  edtUserName, edtApiKey;
	private Button btnVerify;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_login);
		
		edtApiKey = (EditText)findViewById(R.id.edtApiKey);
		edtUserName = (EditText)findViewById(R.id.edtUserName);
		btnVerify = (Button)findViewById(R.id.btnVerify);
		
		btnVerify.setOnClickListener(this);
		
	}

	
	@Override
	public void onClick(View view) {
		if(view==btnVerify)
		{
			if(edtUserName.getText().toString().isEmpty())
			{
				Toast.makeText(LoginActivity.this, "Please enter your username.", Toast.LENGTH_LONG).show();
			}
			else if (edtApiKey.getText().toString().isEmpty())
			{
				Toast.makeText(LoginActivity.this, "Please enter your api key.", Toast.LENGTH_LONG).show();
			}
			else
			{
				UserInfoData userInfoData = UserInfoData.getInstance();
				userInfoData.setUserName(edtUserName.getText().toString().trim());
				userInfoData.setApiKey(edtApiKey.getText().toString().trim());
				
				long id = UserInfoDataManager.getInstance(getApplicationContext()).inserUserInfoData(userInfoData);
				
				Toast.makeText(LoginActivity.this, "User verified successfully, id is :." + id, Toast.LENGTH_LONG).show();
			}
		}
	}

}
